package service.impl;


import dao.PayMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import pojo.paymentM;
import service.PayService;

import java.util.List;
import java.util.UUID;

@Service
@Slf4j
public class PayServiceImpl implements PayService {

    @Autowired
    PayMapper payMapper;

    @Override
    public List<paymentM> getAll() {
        return payMapper.getAll();
    }

    @Override
    public paymentM getOne(int stuId) {
        return payMapper.getOne(stuId);
    }

    @Override
    public Integer add(paymentM paymentM) {
        log.info("paymentM="+paymentM);
        if(paymentM.getId() == null){
            log.warn("payment缺少id,随机生成中");
            paymentM.setId(UUID.randomUUID().toString());
        }
       return payMapper.add(paymentM);
    }

    @Override
    public Integer del(String id) {
       return payMapper.del(id);
    }

    @Override
    public Integer update(paymentM paymentM1) {
       return payMapper.update(paymentM1);
    }

    @Override
    public List<paymentM> getPayByArray(Integer currPage, Integer pageSize) {
        List<paymentM> paymentMS = payMapper.getAll();
        log.info("payment=",paymentMS.toString());
        int firstIndex = (currPage -1 )*pageSize;
        int lastIndex = currPage * pageSize;
        log.info("paymentMS.size=",paymentMS.size());
        log.info("payService.firstIndex="+firstIndex);
        log.info("payService.lastIndex="+lastIndex);
        if((paymentMS.size()-firstIndex)<pageSize){
            paymentMS =paymentMS.subList(firstIndex,paymentMS.size());
        }
        try{
            paymentMS = paymentMS.subList(firstIndex,lastIndex);
        }catch (Exception e){
            e.printStackTrace();
        }
        return paymentMS;
    }

}
